package com.example.mtblog.common;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class data {


    public static final String[] WhiteList = new String[]{
            "/demo/hello","/demo/hello_",
            "/user/login","/user/register","/user/edit","/user/loginByWX",
            "/article/detail","/article/getArticleByAuthor","/article/getArticleByLikeCollect",
            "/personal/get",
            "/comment/getByArticleId","/comment/getByPopingId","/comment/getByParentId",
            "/article/getRecommendArticle","/file/getFile/**"
    };
    public static final String[] AdminList = new String[]{"/demo/admin"};
    public static final String[] UserList = new String[]{
            "/demo/user","/user/logout",
            "/article/add", "/article/likeCollect",
            "/comment/add","/comment/deleteByCommentId","/comment/popingByCommentId",
            "/init/checkToken"
    };





    //用户注册成功后的默认头像
    public  static final String  avatar =  "/file/getFile/image/default/user.jpg" ;


    public static String getRole(String path){

        if(path.startsWith("/file/uploadToQiniu") || path.startsWith("/file/upload"))
            return "user";

        if(path.endsWith(".jpg") || path.endsWith(".png") || path.endsWith(".mp4"))
            return "static";

        if(isContain(path,AdminList))
            return  "admin";

        if(isContain(path,UserList))
            return  "user";
        return null;
    }

    public static boolean isContain(String path ,String [] paths){

        for(String str:paths)
        {
           if(str.equals(path))
               return  true;
        }
        return false;
    }

}


